const { defineConfig } = require("@vue/cli-service");
const { list } = require("./src/mock");
const bodyParser = require("body-parser");
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    setupMiddlewares(middle, { app }) {
      app.use(bodyParser.json());

      app.get("/api/list", (req, res) => {
        res.send({
          code: 200,
          data: list,
        });
      });

      app.post("/api/detail", (req, res) => {
        const { id } = req.body;
        const item = list.find((v) => v.id === id);
        res.send({
          code: 200,
          data: item,
        });
      });

      return middle;
    },
  },
});
